package com.hrm.service.impl;

import com.hrm.dao.HrmApartmentMapper;
import com.hrm.dao.HrmPostMapper;
import com.hrm.dao.HrmStaffMapper;
import com.hrm.model.HrmPost;
import com.hrm.service.HrmPostService;
import com.hrm.util.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("hrmPostService")
public class HrmPostServiceImpl implements HrmPostService{
    @Autowired
    protected HrmPostMapper hrmPostMapper;
    @Autowired
    protected HrmStaffMapper hrmStaffMapper;

    @Override
    public PageView findEntityPageByParam(PageView pageView, Map<String, Object> param) {
        param.put("offset", pageView.getFirstResult());
        param.put("limit", pageView.getPageSize());
        pageView.setQueryResult(hrmPostMapper.getPageNumByMap(param),
                hrmPostMapper.getPageByMap(param));
        return pageView;
    }
    @Override
    public int updatePostInfo(HrmPost hrmPost){
        return hrmPostMapper.updateByPrimaryKeySelective(hrmPost);
    }

    @Override
    public HrmPost getHrmPost(Integer id) {
        return hrmPostMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletePostById(Integer id) {
        hrmPostMapper.deleteByPrimaryKey(id);
        hrmStaffMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<HrmPost> getHrmPost() {
        Map<String, Object> params = new HashMap<String, Object>();
        return hrmPostMapper.getPageByMap(params);
    }
}
